package com.example.demoservice.controller;

import com.example.demoservice.SharedConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class DefAPI {

    @Value("${dataForDemoService}")
    private String dataForDemoService;

    @Autowired
    private DData dData;

    @Autowired
    private SharedConfig sharedConfig;

    @Value("${vmhostname}")
    private String hostname;

    @GetMapping(path = "/some-data")
    public ResponseEntity<String> getSomeData() {
        var body = "test: " + dataForDemoService +
                " | " + sharedConfig.getConsulScopedTestKey() + " | " +
                dData;
        return ResponseEntity.status(HttpStatus.OK)
                .header("X-DEMO-SERVICE", hostname)
                .body(body);
    }
}
